﻿using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using whu2020302051098.Properties;

namespace whu2020302051098
{
    public partial class AttractionIntroForm : Form
    {

        private AxMapControl mapControl = null;
        private IFeatureLayer buildingFeatureLayer = null;
        private IFeatureClass featureClass = null;



        public AttractionIntroForm(AxMapControl aMapControl)
        {
            InitializeComponent();
            InitAttraList();
            this.mapControl = aMapControl;
            for (var index = 0; index < aMapControl.LayerCount; ++index) {
                string name = aMapControl.get_Layer(index).Name;
                if (name == "建筑") {
                    this.buildingFeatureLayer = aMapControl.get_Layer(index) as IFeatureLayer;
                    this.featureClass = buildingFeatureLayer.FeatureClass;
                    break;
                }
            }
            this.attraList.SelectedIndex = 0;

        }

        public void Query(string whereClause) {
            try {
                mapControl.Map.ClearSelection();
                IActiveView pActiveView = mapControl.Map as IActiveView;
                //pQueryFilter的实例化 
                IQueryFilter pQueryFilter = new QueryFilterClass();
                //设置查询过滤条件时，大家有时需要手工编辑这个字符串，保证语法关系的正确性，否则就需要在得到字段值时需要判断“数据类型”
                pQueryFilter.WhereClause = whereClause; //需要有规范的格式
                //search的参数第一个为过滤条件，第二个为是否重复执行
                IFeatureCursor pFeatureCursor = featureClass.Search(pQueryFilter, false);
                //获取查询到的要素 
                IFeature pFeature = pFeatureCursor.NextFeature();
                //判断是否获取到要素 
                while (pFeature != null) {
                    mapControl.Map.SelectFeature(buildingFeatureLayer, pFeature); //选择要素 
                    pFeature = pFeatureCursor.NextFeature(); //游标下移
                }
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                pActiveView.Refresh(); //刷新图层
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }




        void InitAttraList()
        {
            this.attraList.Items.Add("老斋舍");
            this.attraList.Items.Add("理学楼");
            this.attraList.Items.Add("宋卿体育馆");
            this.attraList.Items.Add("万林艺术博物馆");
            this.attraList.Items.Add("牌坊");
            this.attraList.Items.Add("教五楼");
        }

        private void attraList_SelecedIndexChanged(object sender, System.EventArgs e)
        {
            string name = this.attraList.SelectedItem.ToString();
            string whereClause = "";
            if (name == "老斋舍")
            {
                this.ImageLabel.BackgroundImage = Resources.lzs;
                this.introLabel.Text = "作为武汉大学最具代表性的地标建筑之一，老斋舍依山而建、外形统一，气势宏伟，至今仍然保持着民国时期的风韵，来过武大的人想必都会留下一张老斋舍的美照";
                whereClause = "FID=233";
            }
            else if (name == "理学楼")
            {
                this.ImageLabel.BackgroundImage = Resources.lxl;
                this.introLabel.Text = "理学楼的主露穹窿圆屋顶是这栋建筑外表最显著的特色，楼内也是非常值得探索的漂亮世界。";
                whereClause = "FID=1084";
            }
            else if (name == "宋卿体育馆")
            {
                this.ImageLabel.BackgroundImage = Resources.sqtyg;
                this.introLabel.Text = "宋卿体育馆于1935年10月开工，1936年7月竣工，是当时中国规格最高的大学体育馆。现为全国重点文物，继承了武大老建筑一贯的高颜值，也是旅游观光客的最爱之一。";
                whereClause = "FID=227";
            }
            else if (name == "万林艺术博物馆")
            {
                this.ImageLabel.BackgroundImage = Resources.wlysbwg;
                this.introLabel.Text = "万林艺术博物馆由校友陈东升先生捐建，整座建筑造型似一块飞来之石，用铝合金一块一块人工浇筑、敲打而成的外立面、大半悬空的特殊造型使得其非常特别";
                whereClause = "FID=218";
            }
            else if (name == "牌坊")
            {
                this.ImageLabel.BackgroundImage = Resources.pf;
                this.introLabel.Text = "武汉大学牌坊的骨架结构为四柱八棱，象征着欢迎来自四面八方的莘莘学子。";
                whereClause = "FID=214748364";
            }
            else if (name == "教五楼")
            {
                this.ImageLabel.BackgroundImage = Resources.jwl;
                this.introLabel.Text = "教五楼前有一个很大的草坪广场，草坪上有大树，傍晚则经常有人扔飞盘逗狗玩，惠风和畅之时坐或躺在草坪亦十分惬意!";
                whereClause = "FID=209";
            }

            this.attraName.Text = name;
            Query(whereClause);
        }

    }
}
